<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改加工镀铝')" />
    <!--<th:block th:include="include :: datetimepicker-css" />-->
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-aluminized-edit" th:object="${processAluminized}">
            <input name="sign" value="1" type="hidden">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">合并材料编号：</label>
                <div class="col-sm-8">
                    <input name="ribbonNumber" th:field="*{ribbonNumber}" disabled class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-12">
                    <input type="hidden" name="inventoryIds" id="inventoryIds"/>
                    <label class="col-sm-3 control-label">原膜编号：</label>
                    <div class="col-sm-8">
                        <!--<button type="button" class="btn btn-white btn-sm" onclick="addColumn()"><i class="fa fa-plus"> 增加</i></button>-->
                        <!--<button type="button" class="btn btn-white btn-sm" onclick="delColumn()"><i class="fa fa-minus"> 删除</i></button>-->
                    </div>
                    <div class="col-sm-12 table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">镀铝面：</label>
                <div class="col-sm-8">
                    <input name="surfaceName" id="surfaceName" th:field="*{surfaceName}" disabled class="form-control" type="text">
                    <!--<select name="surface" class="form-control m-b"-->
                            <!--th:with="type=${@dict.getType('process_ribbon_state')}">-->
                        <!--<option value="">请选择</option>-->
                        <!--<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{surface}"></option>-->
                    <!--</select>-->
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">质量文字反馈：</label>
                <div class="col-sm-8">
                    <input name="qualityState" th:field="*{qualityState}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">质量图片反馈：</label>
                <div class="col-sm-4">
                    <input id="qualityImg" name="file" multiple type="file" data-show-caption="true">
                </div>
                <div class="col-sm-2">
                    <a class="btn btn-success" onclick='sendFileImg("qualityImg")'><i class="fa fa-plus">图片上传</i></a>
                </div>
                <div class="col-sm-1">
                    <a class="btn btn-warning" onclick='removeImg("qualityImg")'><i class="fa fa-plus">清空图片</i></a>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"></label>
                <div class="col-sm-8">
                    <div class="file-preview qualityImg" style="height: auto">
                    </div>
                    <input name="qualityImg" th:field="*{qualityImg}" type="hidden">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">质量视频反馈：</label>
                <div class="col-sm-6">
                    <input id="qualityVideo" name="file" multiple type="file" data-show-caption="true">
                </div>
                <div class="col-sm-1">
                    <a class="btn btn-success" onclick='sendFile("qualityVideo")'><i class="fa fa-plus">视频上传</i></a>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"></label>
                <div class="col-sm-8">
                    <div class="file-preview qualityVideo" style="height: auto">
                    </div>
                    <input name="qualityVideo" th:field="*{qualityVideo}" type="hidden">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">操作起始时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="startTime" id="startTime" autocomplete="off" th:value="${#dates.format(processAluminized.startTime, 'yyyy-MM-dd HH:mm:ss')}"
                               data-sign=3 class="form-control time-input" data-type="datetime"
                               data-format="yyyy-MM-dd HH:mm:ss" placeholder="yyyy-MM-dd HH:mm:ss" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">抽真空结束时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="vacuoTime" id="vacuoTime" autocomplete="off" th:value="${#dates.format(processAluminized.vacuoTime, 'yyyy-MM-dd HH:mm:ss')}"
                               data-sign=4 class="form-control time-input" data-type="datetime"
                               data-format="yyyy-MM-dd HH:mm:ss" placeholder="yyyy-MM-dd HH:mm:ss" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">操作结束时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="endTime" id="endTime" autocomplete="off" th:value="${#dates.format(processAluminized.endTime, 'yyyy-MM-dd HH:mm:ss')}"
                               data-sign=5 class="form-control time-input" data-type="datetime"
                               data-format="yyyy-MM-dd HH:mm:ss" placeholder="yyyy-MM-dd HH:mm:ss" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">抽真空耗时：</label>
                <div class="col-sm-8">
                    <input id="vacuoConsumeTimeBak" disabled th:field="*{vacuoConsumeTime}" class="form-control" type="text">
                    <input name="vacuoConsumeTime" id="vacuoConsumeTime" th:field="*{vacuoConsumeTime}" class="form-control" type="hidden">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">总耗时：</label>
                <div class="col-sm-8">
                    <input id="consumeTimeBak" disabled th:field="*{consumeTime}" class="form-control" type="text">
                    <input name="consumeTime" id="consumeTime" th:field="*{consumeTime}" class="form-control" type="hidden">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">起始电表度数：</label>
                <div class="col-sm-8">
                    <input name="ammeterStartTime" th:field="*{ammeterStartTime}" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">结束电表度数：</label>
                <div class="col-sm-8">
                    <input name="ammeterEndTime" th:field="*{ammeterEndTime}" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">
                <input type="hidden" name="operatingEquipment" th:field="*{operatingEquipment}" id="equaipment"/>
                <label class="col-sm-3 control-label">操作设备：</label>
                <div class="col-sm-8">
                    <select class="form-control" id="operat-select" onchange="chengeStatus(this.value)">
                        <option value="">请选择</option>
                        <option value="镀铝机">镀铝机</option>
                        <option value="南光机">南光机</option>
                        <option value="宝莱机">宝莱机</option>
                        <option value="其他">其他</option>
                    </select>
                    <input id="other" placeholder="输入设备" class="form-control" type="hidden">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">操作班次：</label>
                <div class="col-sm-8">
                    <input name="operatingNumber" th:field="*{operatingNumber}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">操作人：</label>
                <div class="col-sm-8">
                    <!--<input name="operator" class="form-control" type="text" required>-->
                    <select name="operator" id="operator" class="form-control" data-none-selected-text="请选择">
                        <option value="">请选择</option>
                        <option th:each="user : ${users}" th:text="${user.userName}" th:value="${user.userName}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">技术参数(选填):</label>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">镀膜速度：</label>
                <div class="col-sm-2">
                    <input name="speedBefore" th:field="*{speedBefore}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center"> - </label>
                <div class="col-sm-2">
                    <input name="speedAfter" th:field="*{speedAfter}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center">m/min</label>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">铝层厚度：</label>
                <div class="col-sm-2">
                    <input name="thicknessBefore" th:field="*{thicknessBefore}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center"> - </label>
                <div class="col-sm-2">
                    <input name="thicknessAfter" th:field="*{thicknessAfter}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center">Ω/□</label>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">送丝频率：</label>
                <div class="col-sm-2">
                    <input name="frequencyBefore" th:field="*{frequencyBefore}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center"> - </label>
                <div class="col-sm-2">
                    <input name="frequencyAfter" th:field="*{frequencyAfter}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center">Hz</label>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">蒸发功率：</label>
                <div class="col-sm-2">
                    <input name="powerBefore" th:field="*{powerBefore}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center"> - </label>
                <div class="col-sm-2">
                    <input name="powerAfter" th:field="*{powerAfter}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center">%</label>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">放卷张力：</label>
                <div class="col-sm-2">
                    <input name="unreelingBefore" th:field="*{unreelingBefore}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center"> - </label>
                <div class="col-sm-2">
                    <input name="unreelingAfter" th:field="*{unreelingAfter}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center">N</label>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">收卷张力：</label>
                <div class="col-sm-2">
                    <input name="rollingBefore" th:field="*{rollingBefore}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center"> - </label>
                <div class="col-sm-2">
                    <input name="rollingAfter" th:field="*{rollingAfter}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center">N</label>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">附加张力：</label>
                <div class="col-sm-2">
                    <input name="appendBefore" th:field="*{appendBefore}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center"> - </label>
                <div class="col-sm-2">
                    <input name="appendAfter" th:field="*{appendAfter}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center">N</label>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">真空度G：</label>
                <div class="col-sm-2">
                    <input name="vacuumBefore" th:field="*{vacuumBefore}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center"> - </label>
                <div class="col-sm-2">
                    <input name="vacuumAfter" th:field="*{vacuumAfter}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center">pa</label>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">真空度G5：</label>
                <div class="col-sm-2">
                    <input name="vacuum5Before" th:field="*{vacuum5Before}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center"> - </label>
                <div class="col-sm-2">
                    <input name="vacuum5After" th:field="*{vacuum5After}" placeholder="请输入" class="form-control" type="number">
                </div>
                <label class="col-sm-1 control-label" style="text-align:center">pa</label>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <!--<th:block th:include="include :: datetimepicker-js" />-->
    <script th:inline="javascript">
        var prefix = ctx + "process/aluminized";
        var imgs = [];
        $("#form-aluminized-edit").validate({
            focusCleanup: true
        });
        function getSuffix(url){
            var indexOf = url.indexOf(".")+1;
            return url.slice(indexOf,url.length);
        }
        $(function () {
            var aluminized = [[${processAluminized}]];
            $("#operator option[value= " + aluminized.operator + "]").prop("selected",true);
            if(aluminized.qualityVideo!=null && aluminized.qualityVideo!=""){
                if(getSuffix(aluminized.qualityVideo)=="mp4"){
                    $(".qualityVideo").html('<video src="'+aluminized.qualityVideo+'" controls="controls" style="height: 170px;width: 100%">');
                }else{
                    $(".qualityVideo").html('<img src="'+aluminized.qualityVideo+'" style="height: 100%;width: 100%">');
                }
            }
            if(aluminized.qualityImg!=null && aluminized.qualityImg!=""){
                var p = "";
                var split = aluminized.qualityImg.split(",");
                for (var i = 0; i < split.length; i++) {
                    imgs.push(split[i]);
                    p = p+'<img src="'+split[i]+'" style="height: 100%;width: 100%">';
                }
                $(".qualityImg").html(p);
            }
            var equipment = aluminized.operatingEquipment;
            if(equipment!=null && equipment!=''){
                if(equipment == "镀铝机" || equipment == "南光机"
                    || equipment == "宝莱机"){
                    $("#operat-select option[value= " + equipment + "]").prop("selected",true);
                }else{
                    $("#operat-select option[value= '其他']").prop("selected",true);
                    $("#other").attr("type","text");
                    $("#other").val(equipment);
                }
            }
        });
        function submitHandler() {
            var select = $("#operat-select").val();
            if(select == "其他"){
                $("#equaipment").val($("#other").val());
            }else{
                $("#equaipment").val(select);
            }
            if ($.validate.form()) {
            	
           	 var  ff = $("#surfaceName").val();
        	 console.log(ff+"11111111")
                   var surface ;
                   if(ff == "内" ){
                	   surface = 1 ;
                   }else if(ff =="外"){
                	   surface = 2;
                   }else if( ff = "内+外" ){
                	   surface = 3;
                   }
                   
            	
                $.operate.save(prefix + "/edit", $('#form-aluminized-edit').serialize()+"&surface="+surface);
            }
        }
        //上传多个图片
        function sendFileImg(name) {
            var formData = new FormData();
            //注入 name=file
            var files = $('#'+name)[0].files;
            if(files.length>10){
                layer.alert("上传上限位10");
                return false;
            }
            for (var i = 0; i < files.length; i++) {
                //注意：这里append进去的是File对象，而不是FileList对象
                formData.append("file", files[i]);
            }

            //  var formData = new FormData($('#'+name)[0]);
            // pp.append("file", val);
            $.ajax({
                type: "POST",
                url: ctx + "common/uploadNew",
                data: formData,
                processData: false,
                contentType: false,
                success: function(result) {
                    if (result!=null && result.code == web_status.SUCCESS) {
                        var a = result.url;
                        var p ="";
                        for (var i = 0; i < a.length; i++) {
                            imgs.push(a[i]);
                        }
                        for (var j = 0; j < imgs.length; j++) {
                            p=p+'<img src="'+imgs[j]+'" style="height: 100%;width: 100%">';
                        }
                        $('.'+name).html(p);
                        $('[name="'+name+'"]').val(imgs.join(","));
                    } else {
                        $.modal.alertError("上传失败");
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("图片上传失败");
                }
            });
        }
        function removeImg(name) {
            imgs = [];
            $('.'+name).html("");
            $('#'+name).val("");
            $('[name="'+name+'"]').val("");
        }
        // 上传文件
        function sendFile(name) {
            var val = $('#'+name)[0].files;
            var indexOf = val[0].name.indexOf(".")+1;
            var s = val[0].name.slice(indexOf,val[0].name.length);
            var data = new FormData();
            data.append("file", val[0]);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    if (result!=null && result.code == web_status.SUCCESS) {
                        if(s=="mp4"){
                            $('.'+name).html('<video src="'+result.url+'" controls="controls" style="height: 170px;width: 100%">');
                            $('[name="'+name+'"]').val(result.url);
                        }else{
                            $('.'+name).html('<img src="'+result.url+'" style="height: 100%;width: 100%">');
                            $('[name="'+name+'"]').val(result.url);
                        }
                    } else {
                        $.modal.alertError("上传失败");
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("图片上传失败");
                }
            });
        }
        function chengeStatus(val) {
            if(val == "其他"){
                $("#other").attr("type","text");
            }else{
                $("#other").attr("type","hidden");
            }
        }
// --------------------------------------表格操作------------------------------------------
        //原膜列表
        var data = [[${inventorys}]];
        $(function() {
            var options = {
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'id',
                        title: 'id',
                        visible: false
                    },
                    {
                        field: 'number',
                        align: 'center',
                        title: '原膜编号',
                        formatter: function(value, row, index) {
                            // var obj = {};
                            // obj.index = index;
                            // obj.list = data;
                            // return $("#goodsTypeTpl").tmpl(obj).html();
                            var html = $.common.sprintf("<input class='form-control' disabled type='text' name='goods[%s].number' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                        field: 'factoryName',
                        align: 'center',
                        title: '厂家',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' name='goods[%s].factoryName' disabled type='text' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                        field: 'materialsName',
                        align: 'center',
                        title: '材料名称',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' name='goods[%s].materialsName' disabled type='text' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                        field: 'color',
                        align: 'center',
                        title: '颜色',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' name='goods[%s].color' disabled type='text' value='%s'>", index, value);
                            return html;
                        }
                    },
                    {
                        field: 'mDate',
                        align: 'center',
                        title: '来料日期',
                        formatter: function(value, row, index) {
                            var html = $.common.sprintf("<input class='form-control' name='goods[%s].mDate' disabled type='text' value='%s'>", index, value);
                            return html;
                        }
                    }]
            };
            $.table.init(options);
            show();
        });
        //列表回显
        function show() {
            var table1 = $("#" + table.options.id).bootstrapTable('getData');
            var count = table1.length;
            for (var i = 0; i < data.length; i++) {
                var obj = data[i];
                $("#" + table.options.id).bootstrapTable('insertRow', {
                    index: count,
                    row: {
                        index: $.table.serialNumber(count),
                        id:obj.id,
                        number:obj.number,
                        factoryName: obj.factoryName,
                        materialsName: obj.materialsName,
                        color: obj.color,
                        mDate: obj.mDate,
                    }
                });
            }
        }
    </script>
</body>
</html>
